/*!
 * X weibo JavaScript Library v1.2
 * http://x.weibo.com/
 * 
 * Copyright 2010 SINA Inc.
 * Date: 2010/10/28 21:22:06
 */
 
/*
 * 页面初始化，所有交互初始化入口
 */

(function(X, $){
    var getCfg = X.getCfg,
        Req = X.request,
        Util = X.util,
        Box = X.ui.MsgBox,
        Pagelet = X.ax.Pagelet,
        win = this,
        T = X.ax.Tpl;

    // 监听pipe开始事件
    X.on('pipe.start', function(cfg){
		if(Util.ie6 && $('#weblogo').length){
    		$('#weblogo').fixPng();
		}
        if(!cfg)
            cfg = {};


        // 绑定到空间
    	X.cfg = $.extend({}, win.__gloCfg||{}, cfg);
        
        var uid = X.getUid(),
            page = getCfg('page');
            
        // 绑定全局页面action
        var Action = X.use('action');
        Action.bind(document.body);
        
    	//初始化请求路径
    	cfg.basePath && Req.init(cfg.basePath);
        
        switch (page) {
            case 'guide':
            case 'guide.hot'://首页
            case 'guide.discover':

                //搜索框
                X.use('search', {
                    inputor : 'input.ipt-search',
                    clear : 'a.btn-del-keyword',
                    view : $('.main-search')[0]
                })
            break;
            
            //群组成员管理
            case 'group.admin_member':
                X.use('GroupMemberList', {
                    mouseoverItems : 'a.delete,a.blacklist',
                    view : '#members'
                });
                $('#member_search').focusText('搜索成员名');		
				$('#btn_submit').click(function(){
					if( $('#member_search').val() == '搜索成员名' )
						$('#member_search').val('');
					$('#memberSearchForm').submit();
				});
            break;
            
            //群组信息设置
            case 'group.admin_setting':
                X.use('GroupInfo', {
                    autoRender : true,
                    view : '#group_info'
                });
            break;
            case 'group.admin_report':
			    $('#keyword').focusText('标题/昵称');
				$('#btn_submit').click(function(e){
					var kw = $('#keyword').val();
					if( $.trim(kw).length && kw != '标题/昵称')
						$('#reportSearchForm').submit();
					return false;
				})
			break;
            //组群发表贴子
            case 'group.topic_new':
                //X.use('GroupPost', {view: '#post'});
            break;
            
            //群组黑名单管理
            case 'group.admin_blacklist':
                X.use('GroupMemberList', {
                    mouseoverItems : 'a.blacklist',
                    view : '#members'
                });
                
                var 
                    nickTips = '成员昵称',
                    $nickInput = $('#nickinput').focusText(nickTips);
                
                //添加昵称黑名单
                Action.reg('gpaddbl', function(e){
                    var nickname = $nickInput.val();
                    if (nickname == nickTips) return;
                    
                    e.lock(1);
                    Box.anchorConfirm(e.src, '确定要将<strong>'+Util.escapeHtml(nickname)+'</strong>加入黑名单？', function(btn){
                        if (btn == 'ok') {
                            Req.memberAddBlack(e.get('gid'), nickname, function(r){
                                if (r.isOk()) {
                                    window.location.reload();
                                } else {
                                    Box.alert('提示', r.getMsg());
                                }
                                e.lock(0);
                            }, 2);
                        } else {
                            e.lock(0);
                        }
                    })
                });
            break;
        }
    })
    
    .on('pipe.end', function(){
		//右边顶部浮层,用于显示用户下拉菜单时将所有浮层隐藏
		X.cfg.rightTopFloat = [];
		X.cfg.delFloat = function(id){
			var f = X.cfg.rightTopFloat;
			for(var i=0,j=f.length;i<j;i++){
				if(id == f[i]){
					f.splice(i,1)
					break;
				}					
			}
		}
		
		//游记内容页面
		var page = getCfg('page');
		
		if( /youji|spots.detail|space.ta/.test(page) ){ //登录,注册页
			var sk = X.ui.localStorage.get('searchKey');
			if(sk){
				sk = sk.split('@:@');
				var opt = {'xt':'search','search_type':sk[1],'keyword':sk[0],'is_include':1,'source':'pc'}
				X.ui.localStorage.set('searchKey','');
				Xwb.report.report(opt);
			}
		
		}
		
		//导航
		$('#navArea li').hover(function(){
			var $t = $(this), div = $t.find('div');
			if(div.length){
				$t.find('.main-link').addClass('hover');
				div.cssDisplay(1);
				if(page == 'postcard.create'){//防止明信片制作flash档住
					$('#submenuMask').cssDisplay(1);
				}
			}				
		},function(){
			var $t = $(this), div = $t.find('div');
			if(div.length){
				$t.find('.main-link').removeClass('hover');
				div.cssDisplay(0);	
				if(page == 'postcard.create'){//防止明信片制作flash档住
					$('#submenuMask').cssDisplay(0);
				}
			}
		});
			

			
		//if( !/account/.test(page) )		//feedBack 反馈
			X.use('feedBack').init();	
	
		if(X.getUid() && page != 'user.guideFooter' ){
            // 消息提醒面板
			X.use('notice');		
		}

        switch (page){
			case 'youji':
				(function(){
					if (!$('#tour_panel').length) return;
					
					//判断是否为作者本人访问游记
					var youji = getCfg('youji'),
						isMine = youji.sina_uid == getCfg('uid');
						
				var tour = X.use( 'Tour', { isMine : isMine } );
				})();
				break;
        
        }
    	
        // 搜索框
        $('#xwb_search_form').each(function(){
            X.use('SearchEntry', {view:this}).display(true);
        });

    	//上报数据
        X.report.start();
        var unload = function () {
            X.report.report();
        };
        // 不能用JQ来绑定unload事件
        if (window.addEventListener)
            window.addEventListener("unload", unload, false);
        else if (window.attachEvent)
            window.attachEvent('onunload', unload);
    
                
    	// 顶部菜单效果
    	$('.main-menu>li').slideMenu('>ul','menu-over');
    	
    	// 回到顶部
    	$('#gotop').each(function(){
    	    var jqDoc = $(document);
    	    var jq = $(this);
    	    var ct = $('#container');
    	    var hid = true;
    	    var posed;
    	    var moving;
    	    //jq.css('bottom','95px');
    	    $(window).bind('scroll',function(){
    	        var st = jqDoc.scrollTop(),
                    winHeight = $(window).height();
                    
                if(st < winHeight ){
                    if(!hid){
                        jq.cssDisplay(false);
                        hid = true;
                    }
                    moving = false;
                }else if(!moving){
                    if(hid){
                        jq.cssDisplay(true);
                        hid = false;
                    }
                    /*
                    if(!Util.ie6){
                        // 是否超过ct最底部，超过则持平ct底部
                        var cth = ct.offset().top + ct.height();
                        var eth = jq.offset().top + jq.height();
                        if(eth > cth){
                            if(!posed){
                                jq.css('bottom', jqDoc.height() - cth);
                                posed = true;
                            }
                        }else if(eth < cth && posed){
                            posed = false;
                            jq.css('bottom', '');
                        }
                    }*/
                    
                }
    	    });
    	    
    	    jq.click(function(){
    	        moving = true;
				if(Util.ie6){
					$('html,body').scrollTop(0);
				}else
					$('html,body').animate({'scrollTop': 0}, 150);
    	        return false;
    	    });
    	});
		
		
		
		//unread
		if(X.getUid()){
        	// 发起轮询未读数
        	var checking = false;
        	// 半分钟查一次
        	var interval = 30000;
        	
        	function onUnreadLoad(d){
        	    checking = false;
        	    setTimeout(doCheck, interval);
        	}
        	
        	function doCheck(){
        	    if(!checking){
        	        checking = true;
        	        Req.unread(onUnreadLoad);
        	    }
        	}
        	
        	doCheck();
        }
		
		//登录，注册，个人设置的各页面
		if( /account.login|account.register/.test(page) ){ //登录,注册页
		    var action = page.split('.')[1];
		    Xwb.use("Validator", {
                form: "form",
                trigger: "#btnSubmit",
				decorateTrigger: true,
				haveSpace: false,
     			onsuccess : function(data, next){
				    var self = this, $form = $(self.form);
				    self.lock(1);
					$("#loading").removeClass("hidden"); 
					$("#rstTip").addClass("hidden");
					Req.postReq( Req.mkUrl('jsApi/accountApi', action ), $form.serialize(),function(e){
					    if(e.isOk()){
						    location.href = e.getData().url;
						   	next();
						}else {
						   if( action === 'register') 
								Box.alert('提示', e.getMsg() || e.getError() || '未知的错误' );  //注册页
						   else 
						        $("#rstTip").html( '<span>' + (e.getMsg() || e.getError() || '未知的错误') + '</span><i>&nbsp;</i>' ).removeClass("hidden"); //登录页

						   next();
						}
						$("#loading").addClass("hidden");
						self.lock(0);
					});
         			return false;  // 非FORM提交
     			}
            });
			
			Util.focusEnd($("form input:eq(0)")[0]);
			
			$("#agreement").click(function(){    //注册条款
			    if($(this).attr("checked"))
				    $("#agrWarn").addClass('hidden');
			});
			
			if( action === 'login' ){
				$("input:text").focus(function(){
					$("#rstTip").addClass("hidden");
				});
				var $pw = $("#password"), $pwm = $('#pwMirror');
				$pwm.focus(function(e){		
				    $pwm.addClass('hidden'); 
					$pw.removeClass('hidden');
					Util.focusEnd( $pw[0] );
				});
				
				$pw.blur(function(){
				    if( $.trim($pw.val()) === '' ){
				    	$pw.addClass('hidden');
						$pwm.removeClass('hidden').blur();
					}
				});
		    }
		}
		else if(/account.retrieve_password|account.reset_password/.test( page )){
			var $form = $("form");
			if( !$form[0] )
			    return ;
			var textInps = $form.find('input:text, input:password'), 
			    len = textInps.length,
				$txt_desc = $("#tips_desc").css({overflow:'hidden', display: 'none'}).removeClass('hidden'),
				fCache = {};   //缓存已知出错的帐号密码，以避免过多的请求

			function formSubmit(){
				if( page == 'account.reset_password' )
				    return true;
				var errMsg = '';
			    for(var i=0;i<len;i++) {
				    if(textInps[i].value === '') {
					    var et = textInps[i].getAttribute('emptytip') + ' ';
						if( et ) 
						    errMsg += et;
					}
				}
				if( errMsg ) {
				 	$txt_desc.html( errMsg ).slideDown();
					return false;
				}
				var fstr = $form.serialize();   //表单序列化字符窜
				if( fCache[fstr] !== undefined ){
				    $txt_desc.html(fCache[fstr]).slideDown();
					return false;
				}
				$("#loading").removeClass("hidden");
				Req.postReq( $form.attr('action'), fstr, (function( fstring ){
				    	return function(e){
							if(e.isOk()){
								location.href = e.getData().url || '/';
							}else {
						    	var err = e.getError() || "未知错误";
					    		$txt_desc.html(err).slideDown();
								fCache[fstring] = err;
							}
							$("#loading").addClass("hidden");
						}
					})( fstr )
				);
     		}
			textInps.each(function(index, o){   //给input:text、input:pw添加onEnter事件
			    $(o).keyup(function(e){    
				    if(e.keyCode === 13 )
				        //focus next input or submit form
				        index === len-1 ? formSubmit() : Util.focusEnd(textInps[index+1]);  
				});
				$(o).focus(function(){ 
				    $(this).addClass('input-focus'); 
					if(this.value != '') 
					    $txt_desc.slideUp();
				}).blur(function(){ 
				    $(this).removeClass('input-focus'); 
				});
			});
			
			$("#auth-code").blur(function(){
			    var v = this.value;
				if( v === "" ) 
				    return $txt_desc.html( "验证码不能为空" ).slideDown();
				Req.postReq(Req.mkUrl('jsApi/accountApi','validCode'),{verify_code: this.value},  function(e){
					if(e.isOk()){
						$txt_desc.slideUp();
					}else $txt_desc.html( "验证码错误" ).slideDown();
				});
			})
			
			Util.focusEnd(textInps[0]);  //聚焦到第一个input
			$("#btnSubmit").click( formSubmit );
		}
		else if(page == 'setting.profile' || page == 'setting.changePassWord' ){
			Xwb.use("Validator", {
                form: $("form"),
                trigger: "#submit_btn",
     			onsuccess : function(data, next){
				    var $f = $("form");
					Req.postReq( $f.attr('action'),$f.serialize(),(function(emai,nick){
					    	return function(e){
					    		if( e.isOk() ){
						   			$("input[name=email]").attr('initvalue',emai); //更改初始值，避免多余的检测
						   		    $("input[name=nickname]").attr('initvalue',nick);
									$("#tipSucc").removeClass('hidden');
									if( page == 'setting.changePassWord' ) location.reload(1);
									setTimeout(function(){ $("#tipSucc").addClass('hidden');  }, 2000 );
								}
						   		else Box.error('提示',e.getError());
							}
						})( $("input[name=email]").val(), $("input[name=nickname]").val())
                    );
					next();
         			return false;  // 非FORM提交
     			}
            });
		}
		else if(page == 'setting.privacy'){
		    $("#btn-submit").click(function(){
			    var dm = $("#everyone").attr("checked") ? 0 : 1;
				Req.postReq( Req.mkUrl('jsApi/settingApi','savePrivacy'),"dm="+dm, function(e){
			    	if(e.isOk()){
						$("#tipSucc").removeClass('hidden');
						setTimeout(function(){ $("#tipSucc").addClass('hidden'); }, 2000 );
					}else {
					    Box.error('提示',e.getError());
					}
				})
			})
		}
		else if(/checkEmail/.test(page)){
		    var $timer = $("#timer"), lt = $timer.html();
			window._timer_ = setInterval(function(){
			    $timer.html(--lt);
				if(lt <= 0 ){
				   location.href = $timer.attr('data-url') || '/';
				   clearInterval(window._timer_);
				}
			}, 1000)
		}
		
		//重置密码，额外处理
		if(page == 'account.reset_password'){
		    var $f = $("form");
			$f[0] && Xwb.use("Validator", {
                form: $f,
                trigger: "#btnSubmit",
     			onsuccess : function(data, next){
                    var $f = $("form");
					Req.postReq( $f.attr('action'),$f.serialize(),function(e){
					    if(e.isOk()){
						   location.href = "/index.php";
						}else $("#tips_desc").removeClass('hidden').html(e.getError());
					});
					next();
         			return false;  // 非FORM提交
     			}
            });
		}
		
		var $search_bar = $('#search-box');
        if ($search_bar[0]){
            //导航搜索条
            X.use('search', {
                inputor : $search_bar.find('input.search-input'),
				notNullCS : 'search-btn',
				searchButton : '.search-btn',
				type : 'total',
				selectCls : 'sel',
				unChange : true,
                focusCS : 'search-box-focus',
				viewTemp : 'searchResult',
				sUrl : Req.searchTotal,
				children : 'dt',
				catchClick : true,
				defaultText : '搜索景点/攻略/用户/经验',
				enterInput : function(btn){
					var list = this.jq('.selected');
					if(list.length){
						location.href = list.attr('rel');
					}else btn.click();
				},
				selectPrev : function(e){
					var $prev, lists = this.jq().find('dt,dd');
					if (this.curSelected != -1 ) {
						--this.curSelected;
						this.curSelected = this.curSelected == -1 ? lists.length -1 : this.curSelected;
                        $prev = lists.eq(this.curSelected);
                    }else{
						this.curSelected = lists.length -1;
						$prev = lists.eq(this.curSelected);
                    }
					this.jq('.selected').removeClass('selected');
                    this.select($prev);	
				},
				selectNext : function(e){
					var $next, lists = this.jq().find('dt,dd');
                    if (this.curSelected != -1 ) {
						this.curSelected = (this.curSelected+1) % lists.length;
                        $next = lists.eq(this.curSelected);
                    }else{
						this.curSelected = 0;
						$next = lists.eq(0);
                        //$next = this.jq((objSearch.children || 'LI')+':first');
                    }
					this.jq('.selected').removeClass('selected');
                    this.select($next);
				},
				onmouseover : function(e){
					this.jq('.selected').removeClass('selected');
					var $t = $(e.target), tag = e.target.tagName.toUpperCase();
					if(tag == 'DD' || tag == 'DT'){
						$t.addClass('selected');
					}else{
						var pr = $(e.target).closest('dd');
						pr.length == 0 && (pr = $(e.target).closest('dt'));
						pr.addClass('selected');
					}					
				},
				onmouseout : function(e){
					var $t = $(e.target), tag = e.target.tagName.toUpperCase();
					if(tag == 'DD' || tag == 'DT'){
						$t.removeClass('selected');
					}else{
						var pr = $(e.target).closest('dd');
						pr.length == 0 && (pr = $(e.target).closest('dt'));
						pr.removeClass('selected');
					}
					this.curSelected = -1;
				},
				clickFn : function(e){
					var tag = e.target.tagName.toUpperCase(), url = '';
					if(tag == 'DD' || tag == 'DT'){
						url = $(e.target).attr('rel');
					}else{
						var pr = $(e.target).closest('dd');
						if(pr.length == 0){ 
							pr = $(e.target).closest('dt');
						}else{
							var cls = $(e.target).closest('dl').attr('class'), type = cls == 'place'?1:(cls == 'note' ? 2 : 3);
							X.ui.localStorage.set('searchKey',this.val+'@:@0');
						}
						url = pr.attr('rel');
					}
					url && (location.href = url);

				},
				loadComplete : function(e){
                    if (e.isOk()) {
                        var reqData = e.reqCfg.data, data = e.getData();
                        kw = reqData.q;
                        this.cache[kw] = data;
                        if (this.val === kw) {
                            this.showResult(data, kw)
                        }
                    }
                    
                    this.loadXhr = null;
                },

				showResult : function(data, kw){
					this.curSelected = -1;
					var 
                        escape = Util.escapeHtml,
                        htmlStr = [], kw, NULL = null, 
                        index = 0, kw_escape = escape(kw);
                        
					//景点
					var spots = data.spots, spotsUrl = Req.mkUrl('search','spots',{q:kw});
					htmlStr.push('<dl class="place"><dt rel="'+spotsUrl+'" ><a href="'+spotsUrl+'">搜" '+kw_escape+' "相关景点&raquo;</a></dt>');
					for(var k in spots){
						index ++;
						var spot = spots[k], url = Req.mkUrl('spots', 'detail', {name: spot.name, id: spot.id, '_r':NULL});
                        htmlStr.push(T.parse('search_spots', {
                            url : url,
                            cover : spot.cover,
                            name : spot.name,
                            province : spot.province_name,
                            city : spot.city_name
                        }));
						if(index == 2) break;
					}
					//游记
					var youjis = data.youji, youjiUrl = Req.mkUrl('search','youji',{q:kw});
					htmlStr.push('</dl><dl class="note"><dt rel="'+youjiUrl+'"><a href="'+youjiUrl+'">搜" '+kw_escape+' "相关游记&raquo;</a></dt>');
					for(var k in youjis){						    
						var youji = youjis[k], url = Req.mkUrl('youji','', { id: youji.id, '_r':NULL});
                        htmlStr.push(T.parse('search_dd', {
                            url : url,
                            title : youji.title
                        }));
						//htmlStr.push('<dd rel="'+url+'" ><p class="title"><a href="'+url+'">《'+escape(youji.title)+'》</a></p></dd>');
					}
					//经验
					var exp = data.tips, expUrl = Req.mkUrl('search','exp', {q:kw}), count = 0;
					htmlStr.push('</dl><dl class="exp"><dt rel="'+expUrl+'"><a href="'+expUrl+'">搜" '+kw_escape+' "相关经验&raquo;</a></dt>');
					for(var k in exp){
						count++;
						//var url = Req.mkUrl('space','ta', { id: user.id, '_r':NULL})
						//htmlStr.push('<dd rel="'+expUrl+'"><p class="title"><a href="' + expUrl + '">'+escape(exp[k].text)+'</a></p></dd>');
                        htmlStr.push(T.parse('search_dd', {
                            url : url,
                            title : exp[k].text
                        }));
						if(count >= 2) break;
					}
					//用户
					var users = data.user, userUrl = Req.mkUrl('search','people',{q:kw}), index = 0;
					htmlStr.push('</dl><dl class="user"><dt rel="'+userUrl+'"><a href="'+userUrl+'">搜" '+kw_escape+' "相关用户&raquo;</a></dt>');
					for(var k in users){
						index++;
						var user = users[k], url = Req.mkUrl('space','ta', { id: user.id, '_r':NULL});
                        /*
						htmlStr.push('<dd rel="'+url+'" ><a href="'+url+'" class="pic"><img width="30" height="30" src="'+user.face_xs+'" alt="" /></a>'+
							'<div class="info">'+
								'<p class="name"><a href="'+url+'">'+escape(user.nicknamme)+'</a></p>'+
								'<p>'+area.province+' '+area.city+'</p>'+
							'</div></dd>');
                        */
                        htmlStr.push(T.parse('search_users', {
                            url : url,
                            nickname : user.nickname,
                            face : user.face_xs,
                            location : user.location
                        }))
							if(index == 2) break;
					}
					
					htmlStr.push('</dl>');				
				
					
					$(this.view).html(htmlStr.join('')).highlight(data.keyword);
					
					
					this.display(1);
				},
                view : $search_bar[0]
            });
        }
        
		//用户菜单
		var timer = null, userInfo = $('#userLink div.submenu'), time = 300
		,setTime = function (){
			userInfo.addClass('hidden'); $('#userLink #active').removeClass('active');
			var fl = getCfg('rightTopFloat');
			if(fl.length > 1){
				for(var i=0,j=fl.length;i<j;i++){
					if(fl[i] != '#noticeArea') $(fl[i]).show();
				}
			}else if(fl.length == 1 && fl[0] == '#noticeArea'){
				$('#noticeArea').show();
			}
		};
		$('#userLink #active').mouseover(function(){
			clearTimeout(timer);
			$(getCfg('rightTopFloat').join(',')).hide();
			userInfo.removeClass('hidden'); $(this).addClass('active');
		}).mouseout(function(){
			timer = setTimeout(setTime, time);
		});
		userInfo.mouseover(function(){
			clearTimeout(timer);
		}).mouseout(function(){
			timer = setTimeout(setTime, time);
		});
		
		//用户使用引导
 		(function(){
		    if(X.getUid() ){
				var remind = getCfg('userCfg'), page = getCfg('page'), login = 0, box = '', tpl = X.ax.Tpl, off = {};
				var $user = $('#account'), userName = $user.text();
				function loginTipBox(opt){
					if(box) box.destroy();					
					var option = $.extend({actionMgr:true
					,timer:null
					,cs : opt.cs || ''
					,closeable:true
					,keepTop : true
					,destroyOnClose:true
					,onViewReady:function(){
						//this.jq().offset(off);
						if(this.keepTop)X.use('keepTop').init(this.jq(), '45');							
						this.doSome();
					}
					,destroy :function(d){
						this.jq().remove();						
					}
					,appendTo : opt.appendTo || 'body'	
					, doSome : opt.doSome
					, doAction : opt.doAction
					,onactiontrig : function( e ){
						switch(e.data.e){
							case 'c' : 
								this.doAction(e);
							break;
						}}
					}, opt);
					
					
					box = X.use('Box',option).display(1);
					box.jq().attr('id', option.id);
					getCfg('rightTopFloat').push('#'+option.id);					
				}
				
				function getParam(type){
 					switch(type){
						case 'coin' :
							off = $user.parent().find('img').offset();
							off.top += 35, off.left -= 55;
							return {
								contentHtml : 'msgCoin'
								,doSome : function(){									
									Req.setRemind('coin',1,function(){});
								}
								,cs : 'win-fixed win-notice win-desc'
								,id : 'msgCoin'
								,boxOutterHtml : '<p class="arrow-s1"><i></i></p>'
								,destroy : function(){
									this.jq().remove();
									box = null;
									$('#noticeArea').show();
									X.cfg.delFloat('#msgCoin');
									if(remind.footmark == login)
										setTimeout(function(){loginTipBox(getParam('footmark'));X.use('keepTop').init(box.jq(), 45)},60000);
								}
								,doAction : function(){
									this.destroy();
								}
							}
						break;
						case 'face' :
							//off = $user.parent().find('img').offset();
							//off.top += 35, off.left -= 85;
							return {
								contentHtml : 'msgFace'
								,doSome : function(){Req.setRemind('face', 1,function(){});}
								,cs : 'win-fixed win-upload-tips'
								,id : 'msgFace'
								,mask : true
								,keepTop : false
								,boxOutterHtml : '<p class="arrow-s1"><i></i></p>'
								,destroy : function(){
									X.cfg.delFloat('#msgFace');
									X.ui.Box.prototype.destroy.call(this);
									//this.jq().remove();
									box = null;
									loginTipBox(getParam('coin'));		
								}								
								,doAction : function(e){
									if(e.get('t') == '1')
										location.href = Req.mkUrl('setting','avatar');
								}
							}
							break;
						case 'footmark' :
							off = $('#active').offset();
							off.left = off.left -255;
							off.top = off.top + 45;
							return {
								contentHtml : 'msgFootmark'
								,cs : 'win-fixed win-notice win-fetch-medal'
								,id : 'msgFootmark'
								,appendTo : 'body'
								,doSome : function(){
									Req.setRemind('footmark', 1 ,function(){});
								}
								,doAction : function(){
									location.href = Req.mkUrl('footmark');
								}
								,destroy :function(d){
									this.jq().remove();
									X.cfg.delFloat('#msgFootmark');
									$('#noticeArea').show();									
									setTimeout(function(){loginTipBox(getParam('youji'));},60000);									
								}
							}
						case 'youji' :
							off = $('#active').offset();
							off.left = off.left -255;
							off.top = off.top + 45;
							return {
								contentHtml : 'msgYouji'
								,cs : 'win-fixed win-notice win-fetch-medal'
								,id : 'msgYouji'
								,appendTo : 'body'
								,doSome : function(){
									Req.setRemind('youji',1 ,function(){});
								}
								,doAction : function(){														
									location.href = Req.mkUrl('youji','create');
								}
								,destroy :function(d){
									this.jq().remove();
									X.cfg.delFloat('#msgYouji');	
									$('#noticeArea').show();			
								}
							}							
					} 
				}
				if(page != 'user.guideFooter'){//引导页不触发
					if(remind.face == login && getCfg('svc_id') == 0){
						loginTipBox(getParam('face'));
						if(page == 'youji.create') box.jq().css('z-index',11000);
						$('#noticeArea').hide();
					}else if(remind.coin == login){
						loginTipBox(getParam('coin'));
						$('#noticeArea').hide();
					}else if(remind.footmark == login){
						setTimeout(function(){
							loginTipBox(getParam('footmark'));
							X.use('keepTop').init(box.jq(), 45);
						},1000);	

					}else if(remind.youji == login){					
						setTimeout(function(){
							loginTipBox(getParam('youji'));
							X.use('keepTop').init(box.jq(), 45);
						},1000);	
					}
				}
			}

		})();
		
		//搜索页
		if( /search|search.spots|search.youji|search.people/.test(page) ){ 
			(function(){
				var btn = $('#searchBtn'), ipt = $('#searchIpt');
				btn.click(function(e){
					e.preventDefault();
					var v = Xwb.util.trim(ipt.val());
					if(v){
						location.href = ipt.attr('rel').replace('_KEYWORD_',encodeURIComponent(encodeURIComponent(encodeURIComponent(v))));
					}
				});
				
				ipt.focus(function(){
					ipt.addClass('focus');
				}).blur(function(){
					ipt.removeClass('focus');
				}).keydown(function(e){
					if(e.keyCode == 13)
						btn.click();
				});
			})()
		}
		//小组内容管理
		else if(/group/.test(page)){
			if( 'group.admin_report' == page ){
				$('#sct_chType').change(function(){
					var gid = this.getAttribute('groupid'),
						routoBase = 'group.admin_report',
						type = this.value;
					if( type )
						location.href = Req.mkUrl('group','admin_report',{id: gid, type: type})
				})
			}

			$("#ckb_selAll").click(function(){   //全选
				 $("input:checkbox").attr("checked",$(this).attr("checked"));
			});
		}
		
		if(getCfg('uid'))
			X.use('usersCard',{items:$('body').find('.user_card')});
			
		if(page == 'postcard.share'){

			X.use('ShareByChoose', {
				view : $('div.envelope')[0]}).display(1);
		}
		
		if(page == 'postcard.tpl_list'){
			$('div.tpl-list>ul>li').each(function(){
				$(this).find('div').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');})
			});
		}
		
		/* 全站分享
		 【游记】
			游记详细页 http://www.ziyou.com/youji/XXX
		 【旅途】
			足迹页：http://www.ziyou.com/space.footmark
			旅途-去过：http://www.ziyou.com/journey.hasBeen
			旅途-想去：http://www.ziyou.com/journey.wantTo
		 【小组】
			帖子详细页：http://www.ziyou.com/group.topic/id-641356923354
		*/
		//
		// if( /spots.guide$|space.footmark|journey.hasBeen|journey.wantTo|group.topic$|postcard.detail/ig.test(page) ){
			// $('body').append( T.parse('shareBtns') );
		// }
		// if( page == 'youji' && !/youji\/pid/ig.test(location.href) ){  //预览页去掉
			// $('body').append( T.parse('shareBtns') );
		// }
		// //}
		// Req.bindLst(X.getCfg('uid'), function(rd){
			// if(rd.isOk())
				// X.bindList = rd.getData();   //已绑定列表
			// else
				// X.bindList = {};
		// });   //非异步
		
		//IE6头部用户昵称宽度超过150px设成150px
/* 		if(Util.ie6){
			var account = $('#account').parent();
			if(account.width()>150){
				account.width(150);
			}
		} */
		
    });
	
	
    
    window.xwbPipe = X.ax.PipeMgr;

})(Xwb, $);
